#include "ScoreBoard.h"
#include "Texture.h"
#include "ZoomEffect.h"
#include "GameUtils.h"
#include "Vector.h"
#include "TimeController.h"

ScoreBoard::ScoreBoard(Texture* texNum, int x, int y)
:Object(x, y, 0, 0, 0)
{
	this->texNum = texNum;
	Reset();
}

void ScoreBoard::Reset()
{
	score = 0;
	zoomDelay = 0;
	zoomEffect = 0;
	SetState(SBS_NORMAL);
}

void ScoreBoard::AddScore(int scoreAdd)
{
	score += scoreAdd;
	SetState(SBS_ZOOM_IN);
}

void ScoreBoard::Update()
{
	switch(state)
	{
	case SBS_ZOOM_IN:
		zoomEffect->Update();
		if(zoomEffect->GetIsAlive() == false)
			SetState(SBS_ZOOM);
		break;

	case SBS_ZOOM:
		zoomDelay += TimeController::GetInstance()->GetDtInSecond();
		if(zoomDelay > ZOOM_TIME)
		{
			zoomDelay = 0;
			SetState(SBS_ZOOM_OUT);
		}
		break;
	case SBS_ZOOM_OUT:
		zoomEffect->Update();
		if(zoomEffect->GetIsAlive() == false)
			SetState(SBS_NORMAL);
		break;
	}

	
}

void ScoreBoard::Render()
{
	switch(state)
	{
	case SBS_NORMAL:
		DrawNumber(texNum, NUMBER_SPRITE_WIDTH, NUMBER_SPRITE_HEIGHT, 
			score, pos->x, pos->y, 1, 1, 1);
		break;

	case SBS_ZOOM:
		DrawNumber(texNum, NUMBER_SPRITE_WIDTH, NUMBER_SPRITE_HEIGHT, 
			score, pos->x, pos->y, 2, 2, 1);
		break;

	case SBS_ZOOM_IN: case SBS_ZOOM_OUT:
		DrawNumber(texNum, NUMBER_SPRITE_WIDTH, NUMBER_SPRITE_HEIGHT, 
			score, pos->x, pos->y, zoomEffect->GetZoom(), zoomEffect->GetZoom(), 1);
		break;
	}
	
}

void ScoreBoard::SetState(int state)
{
	this->state = state;
	switch(state)
	{
	case SBS_ZOOM_IN:
		zoomEffect = new ZoomEffect(0, 0, 1, 2, 0, 0, 0.05, 5, 30, 40);
		break;
	case SBS_ZOOM:
		zoomDelay = 0;
		break;
	case SBS_ZOOM_OUT:
		zoomEffect = new ZoomEffect(0, 0, 2, 1, 0, 0, 0.02, 5, 30, 40);
		break;
	}
}

